import unittest
from common.functions import browser_operation
from page.reception.goods.goods_page import GoodsPage


class GoodsTestCase(unittest.TestCase):
    # 大夹子
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = browser_operation()
        # 创建GoodsPage对象
        cls.goods = GoodsPage(driver)
        # 请求目标网址
        cls.goods.get_website(cls.goods.backstage_url)

    # 小后夹子
    def tearDown(self) -> None:
        self.goods.retreat()

    # 家用电器
    def test_01_interface(self):
        # 点击事件
        self.goods.click_classification1()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取到跳转后的页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('家用电器_ECSHOP演示站 - Powered by ECShop', title_name)

    # 数码时尚
    def test_02_interface(self):
        # 点击事件
        self.goods.click_classification2()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('数码时尚_ECSHOP演示站 - Powered by ECShop', title_name)

    # 智能硬件
    def test_03_interface(self):
        # 点击事件
        self.goods.click_classification3()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('智能硬件_ECSHOP演示站 - Powered by ECShop', title_name)

    # 移动电源
    def test_04_interface(self):
        # 点击事件
        self.goods.click_classification4()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('移动电源_ECSHOP演示站 - Powered by ECShop', title_name)

    # 手机类型
    def test_05_interface(self):
        # 点击事件
        self.goods.click_classification5()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('手机类型_ECSHOP演示站 - Powered by ECShop', title_name)

    # 手机
    def test_06_interface(self):
        # 点击事件
        self.goods.click_classification6()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('手机_ECSHOP演示站 - Powered by ECShop', title_name)

    # 充值卡
    def test_07_interface(self):
        # 点击事件
        self.goods.click_classification7()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('充值卡_ECSHOP演示站 - Powered by ECShop', title_name)

    # 服装
    def test_08_interface(self):
        # 点击事件
        self.goods.click_classification8()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('服装_ECSHOP演示站 - Powered by ECShop', title_name)

    # 配件
    def test_09_interface(self):
        # 点击事件
        self.goods.click_classification9()
        # 隐式等待
        self.goods.implicitly_wait()

        # 获取跳转后页面title
        title_name = self.goods.title()
        # 断言
        self.assertEqual('配件_ECSHOP演示站 - Powered by ECShop', title_name)

    @classmethod
    def tearDownClass(cls) -> None:
        # 退出
        cls.goods.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
